<?php 

if ($_SERVER["REQUEST_METHOD"] == "POST"){
 
    $title = "Asig Auto";
    $name = isset($_POST["name"]) ? $_POST["name"] : "";
    $email_address = isset($_POST["email-address"]) ? $_POST["email-address"] : "";
    $phone = isset($_POST["phone"]) ? $_POST["phone"] : "";
    $vrd_file = isset($_POST["vrd_file"]) ? $_POST["vrd_file"] : "";
    
    $name_recipient = isset($_POST["name_recipient"]) ? $_POST["name_recipient"] : "";
    $phone_recipient = isset($_POST["phone_recipient"]) ? $_POST["phone_recipient"] : "";
    $address = isset($_POST["address"]) ? $_POST["address"] : "";
    
 
    $msg = "<h3>Form - " . $title . " </h3>";
    $msg .= "<p>Име: " . $name . "</p>";
    $msg .= "<p>Имейл: " . $email_address . "</p>";
    $msg .= "<p>Телефон: " . $phone . "</p>";
    
    $msg .= "<p>Име наполучател: " . $name_recipient . "</p>";
    $msg .= "<p>Телефон на получател: " . $phone_recipient . "</p>";
        
    $msg .= "<p>Адрес за получаване: " . $address . "</p>";
    
    
    // sender, resep, mail() func, serv resp message in mail_config.php    
    $to = "brokerksi@abv.com, asig@asigauto.com, isipro@gmail.com";
    $subject =  $title; // including the Form Title in the subject
    
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\n";
    $headers .= 'To: <brokerksi@abv.com>' . "\n";
    $headers .= "From: Asig Auto <asig@asigauto.com>";
    $headers .= "Cc: Ivan Ivanov <isipro@gmail.com>";
    
    // Mail () execution
    $mail_success = mail($to, $subject, $msg, $headers);

    // success / failure return message
    if ($mail_success)
    {
        echo "mail success!";
        header('Location: http://asigauto.com');
    }else
    {
        "mail() failed";
        
    }
    
    // clearing cache and variables to ensure correct input processing and deleted old data (when sending more than 2-3 forms one after another)
    $cache_cleared = clearstatcache();
    if ($cache_cleared) { echo "cache cleared success"; } else{  echo "cache cleared success";}
    
    var_dump($_POST);    
    $_POST = array();
}
?>